package org.jeecg.modules.flow.sys.util;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    //
 * 创建人员:    zhaojun
 * 创建时间:    2023-12-05
 */
public class ClassUtil {

    /**
     * 对象转map
     *
     * @param obj
     * @param <T>
     * @return
     * @throws IllegalAccessException
     */
    public static <T> Map<String, Object> convertToMap(T obj) throws IllegalAccessException {
        Map<String, Object> map = new HashMap<>();
        Class<?> clazz = obj.getClass();

        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            Object fieldValue = field.get(obj);

            map.put(fieldName, fieldValue);
        }

        return map;
    }
}
